home *** CD-ROM | disk | FTP | other *** search
/ Sprite 1984 - 1993 / Sprite 1984 - 1993.iso / src / machserver / 1.098 / rpc / rpcStubs.c < prev    next >
Encoding:
C/C++ Source or Header  |  1990-10-09  |  8.7 KB  |  263 lines

  1. /*
  2.  * rpcStubs.c --
  3.  *
  4.  *    The stub procedures for the Rpc service procedures.
  5.  *
  6.  * Copyright 1990 Regents of the University of California
  7.  * Permission to use, copy, modify, and distribute this
  8.  * software and its documentation for any purpose and without
  9.  * fee is hereby granted, provided that the above copyright
  10.  * notice appear in all copies.  The University of California
  11.  * makes no representations about the suitability of this
  12.  * software for any purpose.  It is provided "as is" without
  13.  * express or implied warranty.
  14.  */
  15.  
  16. #ifndef lint
  17. static char rcsid[] = "$Header: /sprite/src/kernel/rpc/RCS/rpcStubs.c,v 9.6 90/10/09 15:46:27 mendel Exp $ SPRITE (Berkeley)";
  18. #endif /* not lint */
  19.  
  20. #include <sprite.h>
  21.  
  22. #include <stdlib.h>
  23. #include <rpc.h>
  24. #include <rpcInt.h>
  25. #include <rpcServer.h>
  26. #include <fsrmtRpcStubs.h>
  27. #include <fsconsist.h>
  28. #include <fsutil.h>
  29. #include <procMigrate.h>
  30. #include <timer.h>
  31. #include <sync.h>
  32. #include <sig.h>
  33. #include <fsio.h>
  34. #include <fsioRpc.h>
  35.  
  36. /*
  37.  * The RPC service procedure switch.  This table and the arguments
  38.  * to the RPC's themselves define the network interface to Sprite.
  39.  * Change things carefully!  You can either add new RPCs to the end,
  40.  * or you can change the RPC_VERSION number defined in rpcPacket.h
  41.  * and create a new in-compatible network interface.
  42.  */
  43.  
  44. RpcService rpcService[RPC_LAST_COMMAND+1] = {
  45.         RpcNull, "0",                          /* 0 - nothing */
  46.         RpcNull, "echo intr",            /* 1 - ECHO1, interrupt level */
  47.         RpcEcho, "echo",            /* 2 - ECHO2, server process */
  48.     RpcEcho, "send",            /* 3 - SEND, server process */
  49.         RpcNull,  "receive",            /* 4 - RECEIVE, unimplemented */
  50.         RpcGetTime, "get time",            /* 5 - GETTIME */
  51.     Fsrmt_RpcPrefix, "prefix",        /* 6 - FS_PREFIX */
  52.     Fsrmt_RpcOpen, "open",            /* 7 - FS_OPEN */
  53.         Fsrmt_RpcRead, "read",            /* 8 - FS_READ */
  54.         Fsrmt_RpcWrite, "write",        /* 9 - FS_WRITE */
  55.         Fsrmt_RpcClose, "close",        /* 10 - FS_CLOSE */
  56.         Fsrmt_RpcRemove, "remove",        /* 11 - FS_UNLINK */
  57.         Fsrmt_Rpc2Path, "rename",        /* 12 - FS_RENAME */
  58.         Fsrmt_RpcMakeDir, "makeDir",        /* 13 - FS_MKDIR */
  59.         Fsrmt_RpcRemove, "rmDir",        /* 14 - FS_RMDIR */
  60.     Fsrmt_RpcMakeDev, "make dev",        /* 15 - FS_MKDEV */
  61.         Fsrmt_Rpc2Path, "hard link",        /* 16 - FS_LINK */
  62.         RpcNull, "sym link",            /* 17 - FS_SYM_LINK */
  63.     Fsrmt_RpcGetAttr, "get attr",        /* 18 - FS_GET_ATTR */
  64.     Fsrmt_RpcSetAttr, "set attr",        /* 19 - FS_SET_ATTR */
  65.     Fsrmt_RpcGetAttrPath, "stat",        /* 20 - FS_GET_ATTR_PATH */
  66.     Fsrmt_RpcSetAttrPath, "setAttrPath",    /* 21 - FS_SET_ATTR_PATH */
  67.     Fsrmt_RpcGetIOAttr, "getIOAttr",    /* 22 - FS_GET_IO_ATTR */
  68.     Fsrmt_RpcSetIOAttr, "setIOAttr",    /* 23 - FS_SET_IO_ATTR */
  69.     Fsrmt_RpcDevOpen, "dev open",        /* 24 - FS_DEV_OPEN */
  70.     Fsrmt_RpcSelectStub, "select",        /* 25 - FS_SELECT */
  71.     Fsrmt_RpcIOControl, "io control",    /* 26 - FS_IO_CONTROL */
  72.     Fsconsist_RpcConsist, "consist",    /* 27 - FS_CONSIST */
  73.     Fsconsist_RpcConsistReply, "consist done",/* 28 - FS_CONSIST_REPLY */
  74.     Fsrmt_RpcBlockCopy, "copy block",    /* 29 - FS_COPY_BLOCK */
  75.     Fsrmt_RpcMigrateStream, "migrate",    /* 30 - FS_MIGRATE */
  76.     Fsio_RpcStreamMigClose, "release",    /* 31 - FS_RELEASE */
  77.     Fsrmt_RpcReopen, "reopen",        /* 32 - FS_REOPEN */
  78.     Fsutil_RpcRecovery, "recover",        /* 33 - FS_RECOVERY */
  79.     Fsrmt_RpcDomainInfo, "domain info",    /* 34 - FS_DOMAIN_INFO */
  80.     Proc_RpcMigCommand, "mig command",    /* 35 - PROC_MIG_COMMAND */
  81.     Proc_RpcRemoteCall, "rmt call",        /* 36 - PROC_REMOTE_CALL */
  82.     Proc_RpcRemoteWait, "remote wait",    /* 37 - PROC_REMOTE_WAIT */
  83.     Proc_RpcGetPCB, "get PCB",        /* 38 - PROC_GETPCB */
  84.     Sync_RemoteNotifyStub, "rmt notify",    /* 39 - REMOTE_WAKEUP */
  85.     Sig_RpcSend, "send signal",        /* 40 - SIG_SEND */
  86.     Fsio_RpcStreamMigCloseNew, "new release",/* 41 - FS_RELEASE_NEW */
  87. };
  88.  
  89.  
  90. /*
  91.  *----------------------------------------------------------------------
  92.  *
  93.  * Rpc_FreeMem --
  94.  *
  95.  *    Free the memory that was allocated for a reply.
  96.  *
  97.  * Results:
  98.  *    None.
  99.  *
  100.  * Side effects:
  101.  *    Memory is freed.
  102.  *
  103.  *----------------------------------------------------------------------
  104.  */
  105. int
  106. Rpc_FreeMem(freeReplyData)
  107.     ClientData        freeReplyData;
  108. {
  109.     Rpc_ReplyMem    *replyMemPtr = (Rpc_ReplyMem *) freeReplyData;
  110.     if (replyMemPtr->paramPtr != (Address) NIL) {
  111.     free(replyMemPtr->paramPtr);
  112.     }
  113.     if (replyMemPtr->dataPtr != (Address) NIL) {
  114.     free(replyMemPtr->dataPtr);
  115.     }
  116.     free((Address) replyMemPtr);
  117.     return(0);
  118. }
  119.  
  120.  
  121. /*
  122.  *----------------------------------------------------------------------
  123.  *
  124.  * RpcNull --
  125.  *
  126.  *    The stub for the null procedure call.
  127.  *
  128.  * Results:
  129.  *    Always return the error code RPC_INVALID_RPC.
  130.  *
  131.  * Side effects:
  132.  *    None.
  133.  *
  134.  *----------------------------------------------------------------------
  135.  */
  136. /*ARGSUSED*/
  137. ReturnStatus
  138. RpcNull(srvToken, clientID, command, storagePtr)
  139.     ClientData srvToken;    /* Handle on server process passed to
  140.                  * Rpc_Reply */
  141.     int clientID;        /* Sprite ID of client host */
  142.     int command;        /* Command identifier */
  143.     Rpc_Storage *storagePtr;    /* The request fields refer to the request
  144.                  * buffers and also indicate the exact amount
  145.                  * of data in the request buffers.  The reply
  146.                  * fields are initialized to NIL for the
  147.                  * pointers and 0 for the lengths.  This can
  148.                  * be passed to Rpc_Reply */
  149. {
  150.     return(RPC_INVALID_RPC);
  151. }
  152.  
  153.  
  154. /*
  155.  *----------------------------------------------------------------------
  156.  *
  157.  * RpcEcho --
  158.  *
  159.  *    Service an echo request.  The input data is simply turned around
  160.  *    to the client.  This type of RPC is used for benchmarks, and
  161.  *    by hosts to query the status of other hosts (pinging).
  162.  *
  163.  * Results:
  164.  *    SUCCESS.
  165.  
  166.  * Side effects:
  167.  *    The echo.
  168.  *
  169.  *----------------------------------------------------------------------
  170.  */
  171. /*ARGSUSED*/
  172. int
  173. RpcEcho(srvToken, clientID, command, storagePtr)
  174.     ClientData srvToken;    /* Handle on server process passed to
  175.                  * Rpc_Reply */
  176.     int clientID;        /* Sprite ID of client host */
  177.     int command;        /* Command identifier */
  178.     Rpc_Storage *storagePtr;    /* The request fields refer to the request
  179.                  * buffers and also indicate the exact amount
  180.                  * of data in the request buffers.  The reply
  181.                  * fields are initialized to NIL for the
  182.                  * pointers and 0 for the lengths.  This can
  183.                  * be passed to Rpc_Reply */
  184. {
  185.     if (command == RPC_ECHO_2) {
  186.     /*
  187.      * The data is stored in buffers specified by the buffer set for
  188.      * the request message.  The correct length of the two parts is
  189.      * computed by the dispatcher and saved in the "actual" size fields.
  190.      */
  191.     storagePtr->replyParamPtr  = storagePtr->requestParamPtr;
  192.     storagePtr->replyParamSize = storagePtr->requestParamSize;
  193.     storagePtr->replyDataPtr   = storagePtr->requestDataPtr;
  194.     storagePtr->replyDataSize  = storagePtr->requestDataSize;
  195.     } else {
  196.     /*
  197.      * RPC_SEND has a null reply already set up by Rpc_Server.
  198.      */
  199.     }
  200.     Rpc_Reply(srvToken, SUCCESS, storagePtr, (int(*)()) NIL, (ClientData) NIL);
  201.     return (SUCCESS);
  202. }
  203.  
  204.  
  205. /*
  206.  *----------------------------------------------------------------------
  207.  *
  208.  * RpcGetTime --
  209.  *
  210.  *    Return the time of day.  The RPC_GET_TIME is done at boot time
  211.  *    by machines and used to initialize their rpcBootID, as well as
  212.  *    set their clock.  The point of the rpcBootID is to have a different
  213.  *    one each time a host boots so others can detect a reboot.  The
  214.  *    time obtained with this is usually overridden, however, with
  215.  *    an 'rdate' done by the bootcmds (much) later in the boot sequence.
  216.  *
  217.  * Results:
  218.  *    If SUCCESS is returned then reply has been sent.  Otherwise caller
  219.  *    will send the error reply.
  220.  *
  221.  * Side effects:
  222.  *    None.
  223.  *
  224.  *----------------------------------------------------------------------
  225.  */
  226. /*ARGSUSED*/
  227. ReturnStatus
  228. RpcGetTime(srvToken, clientID, command, storagePtr)
  229.     ClientData srvToken;    /* Handle on server process passed to
  230.                  * Rpc_Reply */
  231.     int clientID;        /* Sprite ID of client host */
  232.     int command;        /* Command identifier */
  233.     Rpc_Storage *storagePtr;    /* The request fields refer to the request
  234.                  * buffers and also indicate the exact amount
  235.                  * of data in the request buffers.  The reply
  236.                  * fields are initialized to NIL for the
  237.                  * pointers and 0 for the lengths.  This can
  238.                  * be passed to Rpc_Reply */
  239. {
  240.     Rpc_ReplyMem    *replyMemPtr;
  241.     struct timeReturn {
  242.     Time time;
  243.     int offset;
  244.     Boolean DST;
  245.     } *timeReturnPtr;
  246.     
  247.     timeReturnPtr =
  248.     (struct timeReturn *)malloc(sizeof(struct timeReturn));
  249.     Timer_GetTimeOfDay(&timeReturnPtr->time, &timeReturnPtr->offset,
  250.                      &timeReturnPtr->DST);
  251.     storagePtr->replyParamPtr = (Address)timeReturnPtr;
  252.     storagePtr->replyParamSize = sizeof(struct timeReturn);
  253.  
  254.     replyMemPtr = (Rpc_ReplyMem *) malloc(sizeof(Rpc_ReplyMem));
  255.     replyMemPtr->paramPtr = storagePtr->replyParamPtr;
  256.     replyMemPtr->dataPtr = (Address) NIL;
  257.  
  258.     Rpc_Reply(srvToken, SUCCESS, storagePtr, Rpc_FreeMem,
  259.         (ClientData) replyMemPtr);
  260.     return(SUCCESS);
  261. }
  262.  
  263.